from questions.models import All_Questions, Correct_Answers
from django import template


register = template.Library()

@register.filter
def is_multiselect(obj, pk):
    question = All_Questions.objects.filter(id__exact = pk)[0]
    return question.is_multiselect()
    
@register.filter
def is_answer_correct(obj):
    if (Correct_Answers.objects.filter(question = obj.question, answer = obj.id)):
        return 'true'
    else :
        return 'false'
    
@register.filter
def correct_answer_count(obj):
    return obj.correct_answers_set.select_related().count()


    